﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;

namespace Kalficom
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            foreach (string _Str in File.ReadAllLines("config.txt"))
            {
                string[] _StrArray = _Str.Split(Convert.ToChar(":"));
                if (_StrArray[0].ToUpper() == "SERVER") conf.Server = _StrArray[1];
                if (_StrArray[0].ToUpper() == "DATABASE") conf.Database = _StrArray[1];
                if (_StrArray[0].ToUpper() == "LANGUAGE") conf.CurLanguage = _StrArray[1];
            }

            try
            { System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.CreateSpecificCulture(conf.CurLanguage); }
            catch (Exception ex)
            { MessageBox.Show(ex.Message); }
            

            conf.Main = new frmMain();
            if ((new frmLogin()).ShowDialog() == DialogResult.OK)
            {
                Application.Run(conf.Main);
            ReView:
                if (conf.CurUser == 0)
                {
                    Reload(new frmLogin());
                }
            if (conf.CurUser == 0) goto ReView;
            }

                Application.ExitThread();
        }

        static void Reload(Form frm)
        {
            if (frm.ShowDialog() == DialogResult.OK)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.CreateSpecificCulture(conf.CurLanguage);
                conf.Main = new frmMain();
                Application.Run(conf.Main);
            }
            else
            {
                conf.CurUser = -1;
            }

        }
    }
}
